﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace Agile_E
{
    public partial class AddCustomer : System.Web.UI.Page
    {
        protected string fullname;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!User.IsInRole("Manager"))
            {
                Response.Redirect("~/Denied.aspx");
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                Customer newCust = new Customer();
                newCust.Info.LastName = txtlname.Text;
                newCust.Info.MiddleName = txtmname.Text;
                newCust.Info.FirstName = txtfname.Text;
                newCust.Info.Cell = txtcphone.Text;
                newCust.Info.Homephone = txthphone.Text;
                newCust.Info.Workphone = txtWphone.Text;
                newCust.Info.Address = txtstreet.Text;
                newCust.Info.State = txtstate.Text;
                newCust.Info.City = txtcity.Text;
                newCust.Info.Zip = txtzip.Text;
                newCust.Interested = txtInterest.Text;
                newCust.AdditionalInfo = txtnotes.Text;

                DatabaseHandler.connect();
                DatabaseHandler.addCustomer(newCust);
                fullname = newCust.Info.FirstName + " " + newCust.Info.MiddleName + " " + newCust.Info.LastName;
                ((Main)((SearchMP)this.Master).Master).writeStatus(fullname + " has been added", false);
            }
            catch (Exception ex)
            {
                ((Main)((SearchMP)this.Master).Master).writeStatus(ex.Message, true);
            }
        }
    }
}
